import os

import pytest

from recruit.core.config import (
    get_str_env,
    load_database_config,
    DatabaseConfig,
)
from recruit.core.exceptions import ConfigParseError


def test_get_str_env(set_environ: None) -> None:
    assert get_str_env('DB_URI')
    del os.environ['DB_URI']
    with pytest.raises(ConfigParseError):
        get_str_env('DB_URI')


def test_load_database_config(set_environ: None) -> None:
    config = load_database_config()
    assert isinstance(config, DatabaseConfig)
    assert config.db_url == os.getenv('DB_URI')
    del os.environ['DB_URI']
    with pytest.raises(ConfigParseError):
        load_database_config()
